from time import time
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtNetwork import *
from PyQt5.QtCore import *

class Browser(QWebView):
    """
    виджет браузера
    """
    def __init__(self):
        QWebView.__init__(self)
        self.Сookies = QNetworkCookieJar() # куки
        self.page().networkAccessManager().setCookieJar(self.Сookies)
        
    def current_html(self):
        return self.page().mainFrame().toHtml()

    def get(self, url=None):
        # line.setText('{}'.format(url))
        t1 = time()
        if 1:
            loop = QEventLoop()
            timer = QTimer()
            timer.setSingleShot(True)
            timer.timeout.connect(loop.quit)
            self.loadFinished.connect(loop.quit)
            self.load(QUrl(url))
            timeout = 10
            timer.start(timeout * 4000)
            loop.exec_()                                                        # delay here until download finished or timeout

            if timer.isActive():
                timer.stop()                                                    # downloaded successfully
            else:
                print('Выход по таймеру')
            self.html = self.current_html()
